package com.jhc.common.core.config;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;

import java.text.SimpleDateFormat;
import java.util.Date;

@ControllerAdvice
public class RequestAdvice {
    /**
     * 日期格式化 全局配置
     * 等同 spring.mvc.format.date=yyyy-MM-dd HH:mm:ss
     *
     * @param webDataBinder
     */
    @InitBinder
    public void dateFormatter(WebDataBinder webDataBinder) {
        webDataBinder.registerCustomEditor(Date.class, new CustomDateEditor(
                new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"), false
        ));
    }

    @InitBinder
    public void pageBody(WebDataBinder webDataBinder){
//        webDataBinder
    }
}
